﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;


namespace application.control
{
    public class gridOrder : common.controls.baseDataGridView 
    {
        public gridOrder()
        {
            this.AutoGenerateColumns = false;
            this.myAutoFitColumn = ColumnNames.notes.ToString();
            this.LockEdit(true);
        }
        public delegate void ShowOrder(string orderId, string orderType);
        public ShowOrder myShowOrder = null;

        public enum ColumnNames
        {
            orderNo, notes, onDate, editColumn
        };

        public void Init(data.tmpDS.orderBriefDataTable tbl)
        {
            this.DataSource = tbl;
            // 
            // orderNo
            // 
            common.controls.DataGridViewTextBoxColumnExt orderNo = new common.controls.DataGridViewTextBoxColumnExt();
            orderNo.Uppercase = true;
            orderNo.DataPropertyName = tbl.orderNoColumn.ColumnName;
            orderNo.HeaderText = "Số";
            orderNo.Name = ColumnNames.orderNo.ToString();
            orderNo.Width = 160;

            // 
            // onDate
            // 
            DataGridViewTextBoxColumn onDate = new common.controls.DataGridViewTextBoxColumnExt();
            onDate.DataPropertyName = tbl.onDateColumn.ColumnName;
            onDate.HeaderText = "Ngày";
            onDate.Name = ColumnNames.onDate.ToString();
            onDate.Width = 90;

            DataGridViewCellStyle dateType = new DataGridViewCellStyle();
            dateType.Format = "d";
            dateType.NullValue = null;
            onDate.DefaultCellStyle = dateType;

            // 
            // description
            // 
            DataGridViewTextBoxColumn description = new common.controls.DataGridViewTextBoxColumnExt();
            description.DataPropertyName = tbl.notes1Column.ColumnName;
            description.HeaderText = "Diễn giải";
            description.Name = ColumnNames.notes.ToString();

            //editColumn
            common.controls.gridViewImageColumn editColumn = new common.controls.gridViewImageColumn();
            editColumn.Name = ColumnNames.editColumn.ToString(); 
            editColumn.myImageType = common.controls.imageType.Edit;
            editColumn.Width = 25;
            editColumn.HeaderText = "";

            // 
            // myDetailGrid
            // 
            this.Columns.Clear();
            this.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { orderNo, onDate, description, editColumn });
            AutoArrange();
        }

        protected override void OnCellClick(DataGridViewCellEventArgs e)
        {
            base.OnCellClick(e);
            if (myShowOrder == null) return;
            if (e.ColumnIndex < 0 || e.ColumnIndex < 0) return;
            if (this.Columns[e.ColumnIndex].Name != ColumnNames.editColumn.ToString()) return;
            if (this.CurrentRow==null) return;
            data.tmpDS.orderBriefRow row = (data.tmpDS.orderBriefRow)(this.CurrentRow.DataBoundItem as DataRowView).Row;
            myShowOrder(row.orderId, row.orderType); 
        }
    }
}
